﻿using System;
using System.Collections.Generic;
using System.Linq;
using Grundy.Common;

namespace Grundy.Entity
{
    public class AmbiguousLicenseException : Exception
    {
        public List<CustomerLicenseEntitlement> AmbiguousLicenses { get; set; }

        public AmbiguousLicenseException(IEnumerable<CustomerLicenseEntitlement> ambiguousLicenses)
        {
            AmbiguousLicenses = ambiguousLicenses.ToList();
        }
        
        public override string Message
        {
            get
            {
                var l = AmbiguousLicenses
                    .Select(i => "{{ Feature Id: {0}, Feature: {1}, License Entitlement Id: {2}, License: {3}, Product Id: {4}, Product: {5} }}"
                                     .FormatWith(i.License.Feature.Id, i.License.Feature.Name, i.LicenseEntitlementId, i.License.Name, i.ProductId, i.ProductName));
                return "The feature is contained in  multiple licenses. Please specify a license, product or both. Licenses: {0}".FormatWith(string.Join(", ", l));
            }
        }
    }
}